import React from "react";
import { Link, Routes, Route, useLocation } from "react-router-dom";

const Home = () => {
  return <div>这是首页页面</div>;
};

const About = () => {
  return <div>这是关于页面</div>;
};

const Detail = () => {
  return <div>这是详情页页面</div>;
};

const Mine = () => {
  const location = useLocation();
  console.log(location);
  const obj = new URLSearchParams(location.search);
  return (
    <div>
      这是我的页面 - {obj.get("a")} - {obj.get("b")}
    </div>
  );
};

const App = () => {
  return (
    <>
      <h2>react-router-v6-query传参</h2>
      <ul>
        <li>
          <Link to="/home">首页</Link>
        </li>
        <li>
          <Link to="/about">关于页</Link>
        </li>
        <li>
          <Link to="/detail/234">详情页</Link>
        </li>
        <li>
          {/* <Link to="/mine?a=3&b=4">我的</Link> */}
          {/* 如果要传state，放在to的外面 */}
          <Link
            to={{
              pathname: "/mine",
              search: "?a=3&b=4",
            }}
            state={{ x: 10 }}
          >
            我的
          </Link>
        </li>
      </ul>

      <hr />

      <Routes>
        <Route path="/home" element={<Home></Home>}></Route>
        <Route path="/about" element={<About />}></Route>
        <Route path="/detail" element={<Detail />}>
          <Route path=":id" element={<Detail />}></Route>
        </Route>
        <Route path="/mine" element={<Mine />}></Route>
      </Routes>
    </>
  );
};

export default App;
